using KinonekoSoftware.CodariaDB.Documents.Personalities;

namespace KinonekoSoftware.Studio.Models.DataParts.Personality
{
    public sealed class EvaluationPresenter : ObservableObject
    {
        private string        _content;
        private InstanceCache _from;
        private InstanceCache _to;

        public EvaluationPresenter(Evaluation target, InstanceCache character)
        {
            _from  = character;
            Target = target;
        }

        public EvaluationPresenter(InstanceCache to, InstanceCache from)
        {
            _from = from;
            _to   = to;
            Target = new Evaluation
            {
                Id   = ID.Get(),
                From = _from.Id,
                To   = _to.Id,
            };
        }

        public EvaluationPresenter(InstanceCache to, InstanceCache from, Evaluation target)
        {
            _from  = from;
            _to    = to;
            Target = target;
        }

        public string Id                => Target.Id;
        public string CharacterGravatar => From?.Avatar;
        public string CharacterName     => From?.Name;
        public string CharacterIntro    => From?.Intro;

        /// <summary>
        /// 获取或设置 <see cref="Content"/> 属性。
        /// </summary>
        public string Content
        {
            get => Target.Content;
            set
            {
                Target.Content = value;
                SetValue(ref _content, value);
            }
        }

        public InstanceCache From
        {
            get => _from;
            set
            {
                if (value is null)
                {
                    return;
                }

                _from       = value;
                Target.From = value.Id;
                RaiseUpdated(nameof(CharacterGravatar));
                RaiseUpdated(nameof(CharacterName));
                RaiseUpdated(nameof(CharacterIntro));
            }
        }


        public InstanceCache To     => _to;
        public Evaluation    Target { get; }
    }
}